---
import { type CollectionEntry, getCollection } from 'astro:content';
import PostDetail from '@/layouts/PostDetail.astro';
import { getSortedPosts } from '@/utils/getPosts';

export interface Props {
  post: CollectionEntry<'blog'>;
}

export async function getStaticPaths() {
  const posts = await getCollection('blog', ({ data }) => !data.draft);
  const postResult = posts.map(post => ({
    params: { slug: post.slug },
    props: { post },
  }));

  return postResult;
}

const { post } = Astro.props;

const posts = await getCollection('blog');
const sortedPosts = getSortedPosts(posts);
---

<PostDetail post={post} posts={sortedPosts} />
